package singleton;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: lishuo
 * Date: 2023-04-01
 * Time: 12:52
 */
//饿汉模式下实现单例
class Instance {
    private static Instance instance = new Instance();
    public static Instance getInstance() {
        return Instance.instance;
    }
    //私有构造方法，只能在类内使用
    private Instance(){ }
}

public class Singleton {
    public static void main(String[] args) {
        Instance instance = Instance.getInstance();
        //由于设置了私有的构造方法，所以这样写会报错
        //Instance instance1 = new Instance();
    }
}
